package com.ruoyi.system.service.impl;

import java.time.LocalDateTime;
import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.date.LocalDateTimeUtil;
import com.ruoyi.common.utils.uuid.SnUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysArticleCategoryMapper;
import com.ruoyi.system.domain.SysArticleCategory;
import com.ruoyi.system.service.ISysArticleCategoryService;

/**
 * 文章类型Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-01-04
 */
@Service
public class SysArticleCategoryServiceImpl implements ISysArticleCategoryService 
{
    @Autowired
    private SysArticleCategoryMapper sysArticleCategoryMapper;

    /**
     * 查询文章类型
     * 
     * @param id 文章类型主键
     * @return 文章类型
     */
    @Override
    public SysArticleCategory selectSysArticleCategoryById(Long id)
    {
        return sysArticleCategoryMapper.selectSysArticleCategoryById(id);
    }

    /**
     * 查询文章类型列表
     * 
     * @param sysArticleCategory 文章类型
     * @return 文章类型
     */
    @Override
    public List<SysArticleCategory> selectSysArticleCategoryList(SysArticleCategory sysArticleCategory)
    {
        return sysArticleCategoryMapper.selectSysArticleCategoryList(sysArticleCategory);
    }

    /**
     * 新增文章类型
     * 
     * @param sysArticleCategory 文章类型
     * @return 结果
     */
    @Override
    public int insertSysArticleCategory(SysArticleCategory sysArticleCategory)
    {
        if(StringUtils.isEmpty(sysArticleCategory.getParentCode())){
            sysArticleCategory.setParentCode("0");
        }
        sysArticleCategory.setCategoryCode(SnUtil.getInstance().generateId());

        sysArticleCategory.setCreatedTime(LocalDateTime.now());
        sysArticleCategory.setUpdatedTime(LocalDateTime.now());
        return sysArticleCategoryMapper.insertSysArticleCategory(sysArticleCategory);
    }

    /**
     * 修改文章类型
     * 
     * @param sysArticleCategory 文章类型
     * @return 结果
     */
    @Override
    public int updateSysArticleCategory(SysArticleCategory sysArticleCategory)
    {
        sysArticleCategory.setUpdatedTime(LocalDateTime.now());
        return sysArticleCategoryMapper.updateSysArticleCategory(sysArticleCategory);
    }

    /**
     * 批量删除文章类型
     * 
     * @param ids 需要删除的文章类型主键
     * @return 结果
     */
    @Override
    public int deleteSysArticleCategoryByIds(Long[] ids)
    {
        return sysArticleCategoryMapper.deleteSysArticleCategoryByIds(ids);
    }

    /**
     * 删除文章类型信息
     * 
     * @param id 文章类型主键
     * @return 结果
     */
    @Override
    public int deleteSysArticleCategoryById(Long id)
    {
        return sysArticleCategoryMapper.deleteSysArticleCategoryById(id);
    }
}
